package com.mcy.springbatch.reader;

import com.mcy.springbatch.entity.SysUser;
import org.springframework.batch.item.xml.StaxEventItemReader;
import org.springframework.core.io.FileSystemResource;
import org.springframework.oxm.xstream.XStreamMarshaller;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

/**
 * 利用StaxEventItemReader从文件读取xml文件
 * @author : Create By mcy
 * @date : 2019/8/25 22:15:48
 */
@Component
public class ReadUserDataStaxEventItemReader extends StaxEventItemReader {


    public ReadUserDataStaxEventItemReader() {
        setResource(new FileSystemResource("/Users/calon/Desktop/userdata.xml"));
        setFragmentRootElementName("user");
        XStreamMarshaller unMarshaller = new XStreamMarshaller();
        Map<String, Class> map = new HashMap<>();
        map.put("user", SysUser.class);
        unMarshaller.setAliases(map);
        setUnmarshaller(unMarshaller);
    }
}
